﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Qianwei.Model;
using Qianwei.Dac;
using Qianwei.Common;
using Qianwei.Common.Extension;
using MySql.Data.MySqlClient;

namespace Qianwei.Biz
{
    public class PageInfoManager : ManagerBase<PageInfoManager>
    {
        public IList<page_info> QueryPageInfo(string strWhere)
        {
            MySQLHelper msh = new MySQLHelper();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM page_info ");
            if (strWhere != null && strWhere.Trim().Length > 0)
            {
                strSql.Append(" where " + strWhere);
            }
            IList<page_info> pilist = Mapper.DataReaderToList<page_info>(msh.ExecuteReader(strSql.ToString()));
            return pilist;
        }

        public page_info GetModel(string pageName)
        {
            MySQLHelper msh = new MySQLHelper();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select Page_Id, Page_Name, Page_Title, Page_Url, Page_Content  ");
            strSql.Append("  from page_info ");
            strSql.Append(" where Page_Name=@Page_Name");
            MySqlParameter[] parameters = {
					new MySqlParameter("@Page_Name", pageName)
            };

            page_info model = Mapper.DataReaderToObject<page_info>(msh.ExecuteReader(strSql.ToString(), parameters));
            return model;
        }

        public bool Update(page_info model)
        {
            MySQLHelper msh = new MySQLHelper();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update page_info set ");

            strSql.Append(" Page_Content = @Page_Content  ");
            strSql.Append(" where Page_Name=@Page_Name ");

            MySqlParameter[] parameters = {
                        new MySqlParameter("@Page_Name", model.Page_Name) , 
                        new MySqlParameter("@Page_Content", model.Page_Content)
            };

            int rows = msh.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
